﻿using UnityEngine;
using System.Collections;

/// <summary>
/// 跟随摄像机的类
/// </summary>
public class FollowCamera : CameraBase
{
    [SerializeField] private GameObject m_followObject;
    public GameObject FollowObject
    {
        get
        {
            return m_followObject;
        }
    }

    private Transform m_transform;
    private Transform m_followTransform;

    [SerializeField] private bool m_isStartCamera;
    [SerializeField] private bool m_isFollow;

    private Camera m_camera;

    [SerializeField] private float m_smoothDamp = 0.05f;
    private Vector3 m_currentVel;

    void Start()
    {
        m_transform = this.transform;
        m_followTransform = m_followObject.transform;

        m_camera = GetComponentInChildren<Camera>();

        if (m_isStartCamera && null != m_camera)
        {
            CameraMgr.ActiveCamera = m_camera;
        }
    }

    void Update()
    {
        if (m_isFollow)
        {
            Follow();
        }
    }

    private void Follow()
    {
        m_transform.position = Vector3.SmoothDamp(m_transform.position, m_followTransform.position, ref m_currentVel, m_smoothDamp);
    }
}